<?php

namespace App\Admin\Validate;

use App\Common\Validate\Validate;

class ConfValidate extends Validate
{

    public function index($request)
    {
        $method     = $request->getMethod();
        if ($method=='POST'){
            $post       = $request->post();
            $rules      = [
                'title' => 'required',
                'keywords' => 'required',
                'desc' => 'required',
//                'is_log' => 'required',
//                'file_type' => 'required',
//                'file_size' => 'required',
//                'statistics' => 'required',
//                'black_ip' => 'required',
            ];
            $messages   = [
//                'name' => '网站名称必填',
//                'keywords' => '关键词必填',
//                'desc' => '描述必填',
//                'is_log' => '开启日志必填',
//                'file_type' => '上传类型必填',
//                'file_size' => '最大上传值必填',
//                'statistics' => '统计代码必填',
//                'black_ip' => 'IP黑名单必填',
            ];
            $attributes = [];
            if ($rules) {
                return $this->check($post, $rules, $messages, $attributes);
            }
        }
    }


    public function emailsetting($request)
    {
        $method     = $request->getMethod();
        if ($method=='POST'){
            $post       = $request->post();
            $rules      = [
                'smtp' => 'required',
                'username' => 'required',
                'password' => 'required',
                'port' => 'required',
                'email' => 'required',
                'from' => 'required',
            ];
            $messages   = [
                'smtp.required' => 'smtp服务器',
                'username.required' => '发送邮件的邮箱账户',
                'password.required' => '发送邮件的邮箱密码',
                'port.required' => '端口号必填',
                'email.required' => '邮箱必填',
                'from.required' => '发送者必填',
            ];
            $attributes = [];
            if ($rules) {
                return $this->check($post, $rules, $messages, $attributes);
            }
        }
    }

    public function smssetting($request)
    {
        $method     = $request->getMethod();
        if ($method=='POST'){
            $post       = $request->post();
            $rules      = [
                'appkey' => 'required',
                'secretkey' => 'required',
                'FreeSignName' => 'required',
            ];
            $messages   = [
                'appkey' => '阿里大鱼短信接口的AppKey必填',
                'secretkey' => '阿里大鱼短信接口的SecretKey必填',
                'FreeSignName' => '签名必填',
            ];
            $attributes = [];
            if ($rules) {
                return $this->check($post, $rules, $messages, $attributes);
            }
        }
    }

    public function addOne($request)
    {
        $method     = $request->getMethod();
        if ($method=='POST'){
            $post       = $request->post();
            $rules      = [
                'config_key' => 'required',
                'config_value' => 'required',
            ];
            $messages   = [
                'config_key.required' => 'Key必填',
                'config_value.required' => 'Value必填',
            ];
            $attributes = [];
            if ($rules) {
                return $this->check($post, $rules, $messages, $attributes);
            }
        }
    }

    public function editOne($request)
    {
        $method     = $request->getMethod();
        if ($method=='POST'){
            $post       = $request->post();
            $rules      = [
                'id' => 'required',
                'config_key' => 'required',
                'config_value' => 'required',
            ];
            $messages   = [
                'id.required' => '缺少必要参数',
                'config_key.required' => 'Key必填',
                'config_value.required' => 'Value必填',
            ];
            $attributes = [];
            if ($rules) {
                return $this->check($post, $rules, $messages, $attributes);
            }
        }
    }

}